package com.zr.action;

import java.io.IOException;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.zr.datamodel.GoodTypeDM;
import com.zr.service.GoodTypeService;

import net.sf.json.JSONObject;
@Controller
@Scope(value = "prototype") // 以多例的方式生成
public class GoodTypeAction extends ActionSupport implements ServletResponseAware,ServletRequestAware{
	private String  name;
	private String  remark;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getRemark() {
		return remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
	private int page;
	private int rows;
	
	public int getPage() {
		return page;
	}
	public void setPage(int page) {
		this.page = page;
	}
	public int getRows() {
		return rows;
	}
	public void setRows(int rows) {
		this.rows = rows;
	}
	private HttpServletRequest request;   
	private  HttpServletResponse  resp;
	@Resource
	private GoodTypeService goodTypeService;
	/**
	 * 显示货物类别信息
	 */
	public void showGoodType(){
		resp.setCharacterEncoding("utf8");
		JSONObject  obj = goodTypeService.findGoodTypeName(page, rows);
		try {
			resp.getWriter().write(obj.toString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	/**
	 * 新增货物类别信息
	 */
	public void addGoodType(){
		resp.setCharacterEncoding("utf8");
		GoodTypeDM goodType= new GoodTypeDM();
		goodType.setName(name);
		goodType.setRemark(remark);
		goodTypeService.insertGoodType(goodType);
	}
	/**
	 * 删除货物类别信息
	 */
	public void delGoodType(){
		String goodTypes[]= request.getParameterValues("ids[]");
		goodTypeService.delGoodType(goodTypes);
	}
	/**
	 * 修改货物类别信息
	 */
	public void updateGoodType(){
		resp.setCharacterEncoding("utf8");
		GoodTypeDM goodType= new GoodTypeDM();
		goodType.setName(name);
		goodType.setRemark(remark);
		goodTypeService.updateGoodType(goodType);
	}
	@Override
	public void setServletResponse(HttpServletResponse response) {
		// TODO Auto-generated method stub
		this.resp=response;
	}
	@Override
	public void setServletRequest(HttpServletRequest request) {
		// TODO Auto-generated method stub
		this.request=request;
	}

}
